#!/usr/bin/python
#
# Copyright (c) 2008, Mathias Weber
# Copyright (c) 2008, Thomas Stauffer
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this
#   list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright notice,
#   this list of conditions and the following disclaimer in the documentation
#   and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# $Id$

import sys

import direct.directbase.DirectStart
from direct.gui.DirectGui import *
from pandac.PandaModules import TransparencyAttrib

base.setBackgroundColor(0.0, 0.0, 0.2)
base.disableMouse()

gui_map = loader.loadModel("gui/gui.egg")

def test(k):
    print "Test %s" % k

class MyForm(object):
    def __init__(self):
        self.GuiCard = None
        self.RadioButtonSelected = [1]
        self.TestTextValue = "Test"
        self.TestMultiText = "Jeap, \nThis rocks?"
        self.ListElements = ['First', 'Second', 'Third', 'Forth']

    def show(self):
        self.GuiCard, = DirectFrame(geom=gui_map.find("**/background_frame")),
        self.GuiOkButton = DirectButton(command=self.okPressed, relief=None,
                text="OK", text_scale=(0.1,0.1), text_pos=(0, -0.03),
                pos=(-.25, 1.0, -.8),
                geom=(gui_map.find("**/button_normal"), 
                        gui_map.find("**/button_clicked"), 
                        gui_map.find("**/button_hoover"),
                        gui_map.find("**/button_disabled")))
        self.GuiOkButton.reparentTo(self.GuiCard)
        self.GuiCancelButton = DirectButton(command=self.cancelPressed, 
                relief=None,
                text="Cancel", text_scale=(0.1,0.1), text_pos=(0, -0.03),
                pos=(.25, 1.0, -.8),
                geom=(gui_map.find("**/button_normal"), 
                        gui_map.find("**/button_clicked"), 
                        gui_map.find("**/button_hoover"),
                        gui_map.find("**/button_disabled")))
        self.GuiCancelButton.reparentTo(self.GuiCard)
#        if self.RadioButtonSelected == [1]:
                 
        self.GuiRadioButton1 = DirectRadioButton(boxPlacement = 'left',
                variable=self.RadioButtonSelected, value=[1], relief=None,
                boxImage=("gui/radiobutton_normal.png", "gui/radiobutton_hoover.png", "gui/radiobutton_checked.png", None),
                boxRelief=None,
                text="Option 1", scale=(0.1,1.0,0.1), text_pos=(.2,-.03),
                pos=(-.4, 1.0, .85), 
                indicatorValue=(self.RadioButtonSelected==[1]))
        self.GuiRadioButton2 = DirectRadioButton(boxPlacement = 'left',
                variable=self.RadioButtonSelected, value=[2], relief=None,
                boxImage=("gui/radiobutton_normal.png", "gui/radiobutton_hoover.png", "gui/radiobutton_checked.png", None),
                boxRelief=None,
                text="Option 2", scale=(0.1,1.0,0.1), text_pos=(.2,-.03),
                pos=(-.4, 1.0, .7), 
                indicatorValue=(self.RadioButtonSelected==[2]))
        self.GuiRadioButton3 = DirectRadioButton(boxPlacement = 'left',
                variable=self.RadioButtonSelected, value=[3], relief=None,
                boxImage=("gui/radiobutton_normal.png", "gui/radiobutton_hoover.png", "gui/radiobutton_checked.png", None),
                boxRelief=None,
                text="Option 3", scale=(0.1,1.0,0.1), text_pos=(.2,-.03),
                pos=(-.4, 1.0, .55), 
                indicatorValue=(self.RadioButtonSelected==[3]))
 
        self.GuiRadioButton1.setOthers(
                [self.GuiRadioButton2, self.GuiRadioButton3])
        self.GuiRadioButton1.setTransparency(TransparencyAttrib.MAlpha)
        self.GuiRadioButton2.setOthers(
                [self.GuiRadioButton1, self.GuiRadioButton3])
        self.GuiRadioButton2.setTransparency(TransparencyAttrib.MAlpha)
        self.GuiRadioButton3.setOthers(
                [self.GuiRadioButton1, self.GuiRadioButton2])
        self.GuiRadioButton3.setTransparency(TransparencyAttrib.MAlpha)
        self.GuiRadioButton1.reparentTo(self.GuiCard)
        self.GuiRadioButton2.reparentTo(self.GuiCard)
        self.GuiRadioButton3.reparentTo(self.GuiCard)

        self.SingleLineTextEntry = DirectEntry(initialText=self.TestTextValue, 
                scale=.1, focus=0, numLines=1, width=10.0,
                pos=(-.7, 1.0, .35 ), cursorKeys=1, rolloverSound=None,
                clickSound = None, command=self.storeTextSingle)
        self.SingleLineTextEntry.reparentTo(self.GuiCard)
        self.MultiLineTextEntry = DirectEntry(initialText=self.TestMultiText, 
                scale=.1, focus=0, numLines=3, width=10.0,
                pos=(-.7, 1.0, .15 ), cursorKeys=1, rolloverSound=None,
                clickSound = None, command=self.storeTextMulti)
        self.MultiLineTextEntry.reparentTo(self.GuiCard)


    def storeTextSingle(self, value):
        print value

    def storeTextMulti(self, value):
        print value

    def okPressed(self):
        print "OK pressed"
        self.hide()

    def cancelPressed(self):
        print "Cancel pressed"
        self.hide()

    def hide(self):
        print "Got Selected: %s" % self.RadioButtonSelected 
        self.GuiCard.remove()

mf = MyForm()

def close():
    mf.hide()

base.accept("escape", sys.exit)
base.accept("a", render.analyze)
base.accept("o", base.oobe)
base.accept("v", base.bufferViewer.toggleEnable)

mf.show()

run()
